package LC;

import java.util.HashSet;
import java.util.Set;

/**
 * https://leetcode.com/problems/contains-duplicate/description/
 * Given an array of integers, find if the array contains any duplicates.
 * Your function should return true if any value appears at least twice in the array,
 * and it should return false if every element is distinct.
 */
public class LC_217_ContainsDuplicate_Array_HashSet {
    public static void main(String[] args) {
        System.out.println(Solution.containsDuplicate(new int[]{1, 2, 3, 4, 5, 3, 45, 65, 6, 7}));
    }

    static class Solution {
        static boolean containsDuplicate(int[] nums) {
            Set<Integer> unique = new HashSet<>();
            for (int x : nums) {
                if (unique.contains(x)) return true;
                else unique.add(x);
            }
            return false;
        }
    }

    static class Solution_2 {
        static boolean containsDuplicate(int[] nums) {
            Set<Integer> unique = new HashSet<>();
            for (int x : nums) unique.add(x);
            return !(unique.size() == nums.length);
        }
    }
}